import requests
import math
from urllib import parse
from voice_test import decryption_data

headers = {'cp-os': 'android',
           'cp-ver': '1.3.1',
           'cp-uuid': '4cda0b1d-a83d-32b7-a7d1-754db9183f30',
           'cp-abid': '6-100,10-104',
           'cp-channel': 'quick8',
           'cp-time': '1562565896',
           'cp-token': 'ADrryEvNjDG0ZobNC3jmv7SA8MpqQ2sevOjDobnhgqY_',
           'cp-oem': 'HUAWEI',
           'cp-sver': '9',
           'cp-sign': '4fa531838f1e9d32350757f345d91686',
           'cp-appid': '800',
           'Host': 'itest.api.kuai8.mobi',
           'Accept-Encoding': 'gzip',
           'User-Agent': 'okhttp/3.3.1',
           'Connection': 'keep-alive'

           }

params = {
    'smid': 'z1IiJ8WSfa5xqEknG-k9Bsdh4vpPrWB2',
    'count': '10',
    'page': '1'}
data = parse.urlencode(params)

url = 'http://itest.api.kuai8.mobi/1/comment/list.json?smid=z1IiJ8WSfa5xqEknG-k9Bsdh4vpPrWB2&count=10&page=1'
r = requests.get(url, headers=headers)
total = r.json()['result']['total']
pages = total / 10
pages = math.ceil(pages)+1
print('pages======= ',pages)
print('total========',total)
for page in range(1,int(pages)):
    url = 'http://itest.api.kuai8.mobi/1/comment/list.json?' \
          'smid=z1IiJ8WSfa5xqEknG-k9Bsdh4vpPrWB2&count=10&page=%s' % page
    r = requests.get(url, headers=headers)
    comments = r.json()['result']['list']
    comment_list = len(comments)
    for i in range(int(comment_list)):
        comment = comments[i]['content']
        comment_listsmid = comments[i]['smid']
        suid = comments[i]['suid']
        liked_count = comments[i]['liked_count']
        liked = comments[i]['liked']
        from_user = comments[i]['from_user']['suid']
        from_user_nick = comments[i]['from_user']['nick']

        comment_dict = {
            'i': i + 1,
            '评论': comment,
            'suid': suid,
            '点赞数': liked_count,
            '是否点赞': liked,
            '回复评论的用户suid': from_user,
            '回复人的昵称': from_user_nick

        }
        print(comment_dict)
